package com.kate.mall.order.price.coupon;

import com.kate.mall.common.constants.CouponType;
import com.kate.mall.order.dto.CouponDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2021/10/30 21:40
 */
@Component
public class CouponCalculatorFactory {

    /**
     * 现金券计算组件
     */
    @Autowired
    private CashCouponCalculator cashCouponCalculator;
    /**
     * 满减券计算组件
     */
    @Autowired
    private ReachDiscountCouponCalculator reachDiscountCouponCalculator;
    /**
     * 默认计算组件
     */
    @Autowired
    private DefaultCouponCalculator defaultCouponCalculator;

    /**
     * 创建一个优惠券计算组件
     * @param coupon 优惠券
     * @return 优惠券计算组件
     */
    public CouponCalculator create(CouponDTO coupon) {
        if(CouponType.CASH_COUPON.equals(coupon.getType())) {
            return cashCouponCalculator;
        } else if(CouponType.REACH_DISCOUNT_COUPON.equals(coupon.getType())) {
            return reachDiscountCouponCalculator;
        }
        return defaultCouponCalculator;
    }
}
